/*
** ADOBE SYSTEMS INCORPORATED
** Copyright 2012 Adobe Systems Incorporated
** All Rights Reserved.
**
** NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
** terms of the Adobe license agreement accompanying it.  If you have received this file from a
** source other than Adobe, then your use, modification, or distribution of it requires the prior
** written permission of Adobe.
*/
#include "mylib.h"
#include <stdlib.h>
#include <string.h>

int plus(int a, int b){
	return a + b;
}

int plusPtr(int* a, int* b){
	return *a + *b;
}

int stringLength(char* str){
	int i;

	for(i = 0; *(str) != '\0'; i++){
		str++;
	}

	return i;
}

int stringLength2(char str[]){
	int i;

	for(i = 0; str[i] != '\0'; i++){
		// just increment i
	}

	return i;
}

int sumArray(int numbers[4]){
	int i;
	int sum = 0;

	for(i = 0; i < 4; i++){
		sum += numbers[i];
	}

	return sum;
}

void changeStats(HockeyPlayer* p){
	p->jersey = 5;
	p->goals = 60;
}

void incrementEachCharacter(char* str){
	while ((*str) != '\0'){
		*str = *str + 1;
		str++;
	}
	return;
}

int examineBytes(const unsigned char* buffer, int bufferSize){
	int i;
	int stupidSum = 0;
	
	for (i = 0; i < bufferSize; i++){
		stupidSum += *buffer;
		buffer++;
	}
	return stupidSum;
}

int sumGrid(int grid[3][3]){
	int i, j;
	int sum = 0;
	
	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
			sum += grid[i][j];
			
	return sum;
}

void encode(char** out, int* outsize, char* input){
	char* additional = " world";
	char* str = malloc(strlen(input) + strlen(additional));

	int i;
	for (i = 0; i < strlen(input); i++){
		str[i] = input[i];
	}
	int j;

	for (j=0; j < strlen(additional); j++){
		str[i] = additional[j];
		i++;
	}

	*out = str;
	*outsize = strlen(str);
}
